package game.Sokoban;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import com.google.gson.Gson;

import android.app.Activity;
import android.opengl.GLSurfaceView;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Window;
import android.view.WindowManager;

public class SokobanActivity extends Activity {

	GLSurfaceView ourSurface;
    Game game=null;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        //load game data from JSON file
        Gson gson = new Gson();
		try {
			BufferedReader br = new BufferedReader(new InputStreamReader(getAssets().open("sokoban.json")));
			game = gson.fromJson(br,Game.class);
			Log.d("JSON","loaded game data:"+gson.toJson(game));
    	} catch (IOException e) {
			Log.d("JSON",e.getMessage());
		}
        
        // setup view
        requestWindowFeature(Window.FEATURE_NO_TITLE); // requesting to turn the title OFF
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN); // making it full screen
        ourSurface = new GLSurfaceView(this);
        ourSurface.setRenderer(new GLRenderer(this,game));
        setContentView(ourSurface);
    }
    
    protected void onPause(){
    	super.onPause();
    	ourSurface.onPause();
    }
    
    protected void onResume(){
    	super.onResume();
    	ourSurface.onResume();
    }
    public boolean onKeyDown(int keyCode, KeyEvent event) {
    	game.onKeyDown(keyCode, event);
 	
        return super.onKeyDown(keyCode, event);
    }
 
}